package fem2.analysis;

import inf.jlinalg.SolveFailedException;
import fem2.Debugger;
import fem2.Model;
import fem2.strategies.Strategy;

/**
 * Abstract class for all analysis
 * 
 * @author hbui
 * 
 */
public class Analysis {

	private Model model;
	private Strategy strategy = null;

	public Analysis(Model m) {
		model = m;
	}

	/**
	 * get the model
	 * 
	 * @return
	 */
	public Model getModel() {
		return model;
	}

	/**
	 * set the strategy
	 * 
	 * @param s
	 */
	public void setStrategy(Strategy s) {
		strategy = s;
	}

	/**
	 * get the strategy
	 * 
	 * @return
	 */
	public Strategy getStrategy() {
		return strategy;
	}

	/**
	 * analysis
	 */
	public void run() {
		if (strategy != null) {
			Debugger.warn(strategy.getClass().getName());
			try {
				strategy.solve();
			} catch (SolveFailedException e) {
				throw new Error("strategy solve failed");
			}
		} else {
			throw new Error("undefined strategy");
		}
	}
}
